﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Goblinfactory.SpecUtils;

namespace Goblinfactory.NMenu.Framework
{
    public class Menu
    {
        private IEnumerable<string> Options { get; set; }
        public int? Width { get; set; }
        public string ExitText { get; set; }

        public Menu(string[] options, int? width, string exitText)
        {
            options.MustNotBeNull();
            Options = options;
            ExitText = exitText;
            Width = width;
        }

        public HorizontalMenuView GetHorizontalMenu()
        {
            var view = new HorizontalMenuView();
            int i = 1;
            foreach(string o in Options)
            {
                var option = new MenuOption()
                                 {
                                     ContextInfo = o,
                                     Number = i++,
                                     Title = Width.HasValue ? o.Substring(0, Width.Value) : o
                                 };
                view.Options.Add(option);
            }
            view.Options.Add(new ExitMenuOption {ContextInfo = null, Number = i, Title = ExitText ?? "Exit" });
            return view;
        }

    } // class
} // namespace
